<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
			span{
				color: red;
			}
		</style>
		<script type="text/javascript">
			function fun1(){
				var text1=new XMLHttpRequest();
				text1.open("GET","info.txt",true)
				text1.send()
				text1.onreadystatechange=function(){
					if(text1.readyState==4&&text1.status==200){
						let data=text1.responseText
						document.getElementById("d1").innerHTML=data;
					}
					
				}
			}
			
			function fun2(){
				var text2=new XMLHttpRequest();
				text2.open("GET","info.txt",false)
				text2.send()
				let data=text2.responseText
				document.getElementById("d2").innerHTML=data;
			}
		</script>
	</head>
	<body>
		点击按钮获得info.txt的文本数据（异步请求）<br>
		<button type="button" onclick="fun1()()">请求信息</button><br>
		获得的信息：<span id="d1" ></span><hr >
		点击按钮获得info.txt的文本数据（同步请求）<br>
		<button type="button" onclick="fun2()">请求信息</button><br>
		获得的信息：<span id="d2"></span>
	</body>
</html>
